package com.wiscamp.ninechapters.panels.infrastructure.mappers;

import com.wiscamp.ninechapters.panels.infrastructure.views.DictionaryView;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public interface DictionaryViewMapper extends JpaRepository<DictionaryView, Long>, JpaSpecificationExecutor<DictionaryView> {

    @Query(value = "select p from DictionaryView p where p.applicationId = :appId and p.dictionaryCode = :dictionaryCode")
    DictionaryView findByDictionaryCode(long appId, String dictionaryCode);

    @Query(value = "select p from DictionaryView p where p.applicationId = :appId and p.dictionaryName = :dictionaryName")
    Collection<DictionaryView> findListByDictionaryName(long appId, String dictionaryName);

    @Query(value = "select p from DictionaryView p where p.applicationId = :appId and p.dictionaryGroup = :dictionaryGroup and p.enabled")
    Collection<DictionaryView> findListByDictionaryGroup(long appId, String dictionaryGroup);

    Page<DictionaryView> findAll(Specification<DictionaryView> specification, Pageable pageable);
}
